import bus from '@/bus'
let data = {
  form: {
    date: [],
    couponName: '',
    status: ''
  },
  status: 'pass',
  totalItem: 1,
  pageSize: window.$pageSize,
  currentPage: 1,
  columns: [{
    title: '优惠券ID',
    key: 'id',
    minWidth: 200,
    align: 'left'
  }, {
    title: '优惠券名称',
    key: 'couponName',
    minWidth: 200,
    align: 'left',
    tooltip: true
  }, {
    title: '有效期限',
    key: 'usefulDate',
    align: 'left',
    minWidth: 280,
    render: (h, params) => {
      let row = params.row
      let text = ''
      if (!row.validityStartDate || !row.validityEndDate) {
        text = row.validityDays + '天'
      } else {
        text = row.validityStartDate + '-' + row.validityEndDate
      }
      return h('div', text)
    }
  }, {
    title: '发行量',
    key: 'amount',
    align: 'right',
    minWidth: 120,
    render: (h, params) => {
      let text = params.row.amount < 0 ? '不限' : params.row.amount
      return h('div', text)
    }
  }, {
    title: '剩余发行量',
    key: 'receiveAmount',
    align: 'right',
    minWidth: 120,
    render: (h, params) => {
      let text = ''
      if (params.row.amount < 0) {
        text = '不限'
      } else {
        text = params.row.amount - params.row.receiveAmount
      }
      return h('div', text)
    }
  }, {
    title: '面额/条件',
    key: 'denomination',
    align: 'left',
    minWidth: 120,
    render: (h, params) => {
      let row = params.row
      let denominationCondition
      // let denominationCondition = row.couponDiscountType == 'DISCOUNT_COUPON' ? row.discountRuleDescription + '折' : row.denomination + '元/满' + row.useCondition + '元'
      switch (row.couponDiscountType) {
        case 'DISCOUNT_COUPON':
          const length = row.discountGroupList.length
          if (length === 1) {
            denominationCondition = `${row.discountGroupList[0].discount}折`
          } else {
            denominationCondition = `${row.discountGroupList[0].discount} - ${row.discountGroupList[length - 1].discount}折`
          }
          break
        case 'DENOMINATION_COUPON':
          denominationCondition = `${row.denomination}元/满${row.useCondition}元`
          break
        case 'CASH_COUPON':
          denominationCondition = `${row.denomination}元`
          break
      }
      return h('div', denominationCondition)
    }
  }, {
    title: '推广方式',
    key: 'receiveMethod',
    align: 'left',
    minWidth: 120,
    render: (h, params) => {
      let text = ''
      switch (params.row.receiveMethod) {
        case 'SELLER_SEND':
          text = '卖家发放'
          break
        case 'BUYER_RECEIVE':
          text = '买家领取'
          break
      }
      return h('div', text)
    }
  }, {
    title: '状态',
    key: 'couponStatus',
    align: 'left',
    minWidth: 120,
    filters: [{
      value: 10,
      label: '未启用'
    }, {
      value: 11,
      label: '启用'
    }, {
      value: 12,
      label: '已关闭'
    }],
    filterMultiple: false,
    filterRemote (data, key, target) {
      this.$bus.$emit('statusSelect', data)
    },
    render: (h, params) => {
      let text = ''
      switch (params.row.couponStatus) {
        case 'OPEN':
          text = '启用'
          break
        case 'NO_OPEN':
          text = '未启用'
          break
        case 'CLOSE':
          text = '已关闭'
          break
      }
      return h('div', text)
    }
  }, {
    title: '操作',
    key: 'operate',
    align: 'right',
    width: 150,
    fixed: 'right',
    render: (h, params) => {
      const row = params.row
      // 复制dis
      let orDis = row.couponPromotionType === 'FULL_COUPON_ACTIVE_COUPON'
      // 直接发放dis
      let seDis = true
      if (row.couponStatus === 'CLOSE') {
        seDis = true
      } else if (!row.sendByBarcodeRight && !row.sendByQuantityRight) {
        seDis = true
      } else {
        seDis = row.couponPromotionType === 'FULL_COUPON_ACTIVE_COUPON'
      }
      // addDis 加发行量dis
      let addDis = true
      if (row.couponStatus === 'CLOSE') {
        addDis = true
      } else if ((row.couponStatus === 'NO_OPEN' || row.couponStatus === 'OPEN') && row.amount >= 0) {
        addDis = false
      } else if (row.receiveMethod === 'SELLER_SEND' && row.amount >= 0) {
        addDis = false
      }
      // edDis 编辑商品dis
      let edDis = true
      if ((row.couponStatus === 'NO_OPEN' || row.couponStatus === 'OPEN') && row.couponDiscountType !== 'CASH_COUPON') {
        edDis = false
      } else if (params.row.couponStatus === 'CLOSE') {
        edDis = true
      } else if (row.receiveMethod === 'SELLER_SEND' && row.couponDiscountType !== 'CASH_COUPON') {
        edDis = false
      }
      // clDis 关闭dis
      let clDis = true
      if (row.couponStatus === 'CLOSE') {
        clDis = true
      } else if (row.couponStatus === 'OPEN') {
        clDis = false
      }
      let detailBtn = h('Button', {
        props: {
          size: 'small',
          type: 'default'
        },
        style: {
          marginRight: '5px'
        },
        on: {
          click: () => {
            window.$router.push({
              name: 'coupon/detail',
              query: {
                id: row.id
              }
            })
          }
        }
      }, '查看')
      let drop = h('Dropdown', {
        props: {
          transfer: true
        }
      }, [
        h('Button', {
          props: {
            size: "small",
            type: 'primary'
          }
        }, ['更多',
          h('Icon', {
            props: {
              type: "ios-arrow-down"
            }
          })
        ]),
        h('DropdownMenu', {
          slot: 'list'
        }, [
          h('DropdownItem', {
            props: {
              disabled: orDis
            },
            nativeOn: {
              click:() => {
                if(!orDis) bus.$emit('onCopyCoupon', { item: row, index: params.index })
              }
            }
          }, "复制"),
          h('DropdownItem', {
            props: {
              disabled: row.couponStatus === 'CLOSE' || row.couponStatus === 'OPEN'
            },
            nativeOn: {
              click: () => {
                if (row.couponStatus === 'CLOSE' || row.couponStatus === 'OPEN') return
                bus.$emit('onOpen', { item: row, index: params.index })
              }
            }
          }, '启用'),
          h('DropdownItem', {
            props: {
              disabled: clDis
            },
            nativeOn: {
              click:() => {
                if (!clDis) bus.$emit('onClose', { item: row, index: params.index })
              }
            }
          }, '关闭'),
          h('DropdownItem', {
            props: {
              disabled: seDis
            },
            nativeOn: {
              click:() => {
                if (!seDis) bus.$emit('showModal', { id: params.row.id, type: params.row.couponDiscountType })
              }
            }
          }, '直接发放'),
          h('DropdownItem', {
            props: {
              disabled: addDis
            },
            nativeOn: {
              click:() => {
                if (!addDis) bus.$emit('onAddSum', params.row.id)
              }
            }
          }, '加发行量'),
          h('DropdownItem', {
            props: {
              disabled: edDis
            },
            nativeOn: {
              click:() => {
                if (!edDis) bus.$emit('onEditGoods', params.row.id)
              }
            }
          }, '编辑商品'),
        ])
      ])
      // let originalBtn = h('Button', {
      //   props: {
      //     size: 'small',
      //     type: 'default',
      //     disabled: orDis
      //   },
      //   style: {
      //     'margin-right': '5px'
      //   },
      //   on: {
      //     click: () => {
      //       bus.$emit('onCopyCoupon', { item: row, index: params.index })
      //     }
      //   }
      // }, '复制')
      // let openBtn = h('Button', {
      //   props: {
      //     size: 'small'
      //   },
      //   style: {
      //     marginRight: '5px'
      //   },
      //   on: {
      //     click: () => {
      //       bus.$emit('onOpen', { item: row, index: params.index })
      //     }
      //   }
      // }, '启用')
      // let closeBtn = h('Button', {
      //   props: {
      //     size: 'small',
      //     disabled: clDis
      //   },
      //   style: {
      //     marginRight: '5px'
      //   },
      //   on: {
      //     click: () => {
      //       bus.$emit('onClose', { item: row, index: params.index })
      //     }
      //   }
      // }, '关闭')

      // let sendBtn = h('Button', {
      //   props: {
      //     size: 'small',
      //     disabled: seDis
      //   },
      //   style: {
      //     marginRight: '5px'
      //   },
      //   on: {
      //     click: () => {
      //       bus.$emit('showModal', { id: params.row.id, type: params.row.couponDiscountType })
      //     }
      //   }
      // }, '直接发放')
      // let AddSumBtn = h('Button', {
      //   props: {
      //     size: 'small',
      //     type: 'primary',
      //     disabled: addDis
      //   },
      //   style: {
      //     marginRight: '5px'
      //   },
      //   on: {
      //     click: () => {
      //       bus.$emit('onAddSum', params.row.id)
      //     }
      //   }
      // }, '加发行量')
      // let editGoods = h('Button', {
      //   props: {
      //     size: 'small',
      //     type: 'primary',
      //     disabled: edDis
      //   },
      //   style: {
      //     marginRight: '5px'
      //   },
      //   on: {
      //     click: () => {
      //       bus.$emit('onEditGoods', params.row.id)
      //     }
      //   }
      // }, '编辑商品')
      // 未启用 显示         查看，启用，复制，统计
      // 启用（使用中） 显示  查看，关闭, 复制，统计
      // 已关闭 显示         查看，复制，统计
      // if (row.couponStatus === 'CLOSE' || row.couponStatus === 'OPEN') {
      //   return h('div', [AddSumBtn, originalBtn, detailBtn, closeBtn, sendBtn, editGoods])
      // } else {
      //   return h('div', [AddSumBtn, originalBtn, detailBtn, openBtn, sendBtn, editGoods])
      // }
      return h('div', [detailBtn, drop])
    }
  }],
  data: []
}

export default data
